package com.hb.guli.common.base.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author jack
 * @date 2023/7/4 22:12
 * @description: 输出错误的堆栈信息
 */
public class ExceptionUtils {

    public static String getMessage(Exception e) {

        try (StringWriter stringWriter = new StringWriter();
             PrintWriter printWriter = new PrintWriter(stringWriter);
        ) {
            // 将出错的堆栈信息输出到 printWriter
            e.printStackTrace(printWriter);
            printWriter.flush();
            stringWriter.flush();
            return stringWriter.toString();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
